Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

331
Visualizações
Vue3 won't trigger watch when using v-model:prop="data"

I'm creating a child component for my filters which should be updated when the user changes some input values... The problem is that when I emit the new data into the parent component the watch won't trigger! Please review my code to see where I went wrong...

Parent Component

Defining the component
<FiltersComponent v-model:filters="filters" />
Defining the watch expression
watch(filters, (value) => {
  getAccounts(value);
});

Child Component

const emits = defineEmits(['update:filters']);
const props = defineProps({
  filters: {
    type: Object,
    default: () => ({
      ...
    }),
    required: true,
  },
});

function updateFilters(newValue, property) {
  console.log('updateFilters', newValue, property);
  emits('update:filters', { ...props.filters, [property]: newValue });
}

note: the console.log prints the newValue and property correctly but the watch never happens!

PS: I used the v-on:update:filters="getAccounts(filters)" inside parent component too. but the filters data is not updated inside function call...

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You need to set deep to true when watching an array or object so that Vue knows that it should watch the nested data for changes. Try using this:

    watch(filters, (value) => {
      getAccounts(value);
    },
      {
       deep: true
      }
    );

For reference please review the vue 3 documentation: https://v3.vuejs.org/guide/migration/watch.html#_3-x-syntax

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda